// 项目完整性测试脚本
const fs = require('fs');
const path = require('path');

console.log('=== 项目完整性检查 ===');

// 检查关键文件是否存在
const criticalFiles = [
  'app.js',
  'app.json',
  'app.wxss',
  'project.config.json',
  'backend/server.js',
  'backend/package.json',
  'utils/api.js',
  'utils/util.js',
  'pages/index/index.js',
  'pages/login/login.js',
  'custom-tab-bar/index.js'
];

let allFilesExist = true;
criticalFiles.forEach(file => {
  const exists = fs.existsSync(file);
  console.log(`${exists ? '✓' : '✗'} ${file}`);
  if (!exists) allFilesExist = false;
});

console.log('\n=== 后端依赖检查 ===');
try {
  const backendPackage = JSON.parse(fs.readFileSync('backend/package.json', 'utf8'));
  console.log('后端依赖:', Object.keys(backendPackage.dependencies || {}).join(', '));
} catch (e) {
  console.log('后端package.json读取失败');
}

console.log('\n=== 项目结构检查 ===');
function checkDir(dir, depth = 0) {
  const indent = '  '.repeat(depth);
  try {
    const items = fs.readdirSync(dir);
    items.forEach(item => {
      const fullPath = path.join(dir, item);
      const stat = fs.statSync(fullPath);
      if (stat.isDirectory()) {
        console.log(`${indent}📁 ${item}/`);
        if (depth < 2) checkDir(fullPath, depth + 1);
      } else {
        console.log(`${indent}📄 ${item}`);
      }
    });
  } catch (e) {
    console.log(`${indent}❌ 无法访问目录: ${dir}`);
  }
}

checkDir('.');

console.log('\n=== 检查结果 ===');
if (allFilesExist) {
  console.log('✅ 项目文件完整性检查通过');
  console.log('💡 建议：使用微信开发者工具打开项目进行测试');
} else {
  console.log('❌ 项目文件存在缺失，需要修复');
}